#!/usr/bin/env python
# -*- coding: utf-8 -*-

# pywordlist.It's a WordList Maker
# Copyright (C) 2009,res0w
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
'''
Created on 2009-11-22

@author: res0w
'''
import random,os
from datetime import date
class Core():
    '''核心类：core,to complete almost job '''
    def __init__(self):   
        self.wordlist=[]
        self.ranlist=[]
    
    def showRanList(self,amount=10):
        '''把amount转换成数字，并生成对应数量的list'''
        amount=int(amount) 
        utils.mkdic()
        self.wordlist=utils.wordlist
        list=random.sample(self.wordlist,amount)
        self.ranlist=list
        print '\n'.join(word for word in list)
        
    def writeRanList(self):
        filename=str(date.today().year)+str(date.today().month
                                            )+str(date.today().day)+'list'
        if os.path.isfile(os.path.abspath(filename))==False:
            open(filename,'w').write('\n'.join(word for word in self.ranlist))
        else:
            print 'Word List has been maked before!'
           
class Utils():
    '''工具类'''
    def __init__(self):
        self.wordlist=[]
    
    def mkdic(self):
        wordsfile = open("words.txt")
        try:
            for words in wordsfile:
                if len(words.split()) != 0:
                    self.wordlist.append(words.split()[0])
        finally:
            wordsfile.close()  

utils=Utils()
    
        
#全局实例化
core=Core()

    
    
